package com.imut.oa.controller.admin;

import com.imut.oa.common.BaseResponse;
import com.imut.oa.common.PageResult;
import com.imut.oa.common.ResultUtils;
import com.imut.oa.pojo.dto.DepartmentAddDTO;
import com.imut.oa.pojo.dto.DepartmentPageQueryDTO;
import com.imut.oa.service.DepartmentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/department")
@Slf4j
@Tag(name = "部门管理")
public class DepartmentController {
    @Resource
    private DepartmentService departmentService;

    /**
     * 部门分页查询
     * @param departmentPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @Operation(summary = "部门分页查询")
    public BaseResponse<PageResult> page (DepartmentPageQueryDTO departmentPageQueryDTO){
        log.info("分页查询：{}",departmentPageQueryDTO);
        PageResult pageResult = departmentService.page(departmentPageQueryDTO);
        return ResultUtils.success(pageResult);
    }
/**
     * 新增部门
     * @param departmentAddDTO
     * @return
     */
    @PostMapping
    public BaseResponse add(@RequestBody DepartmentAddDTO departmentAddDTO) {
        log.info("新增部门：{}", departmentAddDTO);
        departmentService.save(departmentAddDTO);
        return ResultUtils.success();
    }
    /**
     * 修改部门
     * @param departmentAddDTO
     * @return
     */
    @PutMapping
    public BaseResponse update(@RequestBody DepartmentAddDTO departmentAddDTO) {
        log.info("修改部门：{}", departmentAddDTO);
        departmentService.updateDepartment(departmentAddDTO);
        return ResultUtils.success();
    }
    /**
     * 删除部门
     * @param id
     * @return
     */
    @DeleteMapping()
    public BaseResponse remove(Long id) {
        log.info("删除部门：{}", id);
        departmentService.removeDepartmentById(id);
        return ResultUtils.success();
    }
    /**
     * 获取所有部门
     * @return
     */
    @GetMapping("/all")
    public BaseResponse<Object> getAll() {
        log.info("获取所有部门");
        return ResultUtils.success(departmentService.list());
    }
}
